package org.huang.properties.bean;

import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * @描述: 用于测试配置验证的bean
 * @作者 Mr.Huang
 * @创建时间 2017-08-08
 * @版本: 1.0
 */
@ConfigurationProperties(prefix="valid")
@Validated
@Component
public class ValidBean {
    @NotBlank(message = "用户名不能为空")
    private String username;
    @NotBlank(message = "密码不能为空")
    private String password;
    @NotBlank(message = "编码不能为空")
    private String code;
    @Valid
    private ValidSubBean validSubBean;

    public ValidSubBean getValidSubBean() {
        return validSubBean;
    }

    public void setValidSubBean(ValidSubBean validSubBean) {
        this.validSubBean = validSubBean;
    }


    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }


    public static class ValidSubBean{
        @NotBlank
        private String text;
        @NotEmpty
        private List<String> subs = new ArrayList<String>();

        public String getText() {
            return text;
        }

        public void setText(String text) {
            this.text = text;
        }

        public List<String> getSubs() {
            return subs;
        }

        public void setSubs(List<String> subs) {
            this.subs = subs;
        }

        @Override
        public String toString() {
            return "ValidSubBean{" +
                    "text='" + text + '\'' +
                    ", subs=" + subs +
                    '}';
        }
    }

    @Override
    public String toString() {
        return "ValidBean{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", code='" + code + '\'' +
                ", validSubBean=" + validSubBean +
                '}';
    }
}
